package com.gyt.framework.common.all;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * @author v_yantgao
 */
public class DateUtil {

    /**
     * 返回指定格式时间
     */
    public static String timeofnowFormat(Date date,String format) {
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        if (date == null)
            return "";
        return sdf.format(date);
    }

    /**
     * 返回当前时间
     */
    public static String timeofnow() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Calendar curcal = Calendar.getInstance();
        return sdf.format(curcal.getTime());
    }

    /**
     * 得到指定时间的时间戳
     */
    public static long getTransTime(String transTime){
        try{
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date d = sdf.parse(transTime);
            return d.getTime();
        }catch (Exception e) {
            e.printStackTrace();
        }
        return 0;
    }

}
